package driver

import (
	"context"
	"log"

	"cloudea.com/k8s-csi-fs/driver/proto"

	wrappers "github.com/golang/protobuf/ptypes/wrappers"
)

type IdentityServer struct {
	proto.UnimplementedIdentityServer
}

/*
*
获取插件名和版本号
*/
func (IdentityServer) GetPluginInfo(context.Context, *proto.GetPluginInfoRequest) (*proto.GetPluginInfoResponse, error) {
	name := "com.cloudea.csi.fs"
	version := "1.0.0"
	log.Printf("GetPluginInfo 被调用: name = %s, version = %s \n", name, version)
	return &proto.GetPluginInfoResponse{
		Name:          name, // 反向DNS
		VendorVersion: version,
	}, nil
}

/** 获取插件的能力 */
func (IdentityServer) GetPluginCapabilities(context.Context, *proto.GetPluginCapabilitiesRequest) (*proto.GetPluginCapabilitiesResponse, error) {
	log.Println("GetPluginCapabilities 被调用")
	resp := &proto.GetPluginCapabilitiesResponse{
		Capabilities: []*proto.PluginCapability{
			{
				Type: &proto.PluginCapability_Service_{
					Service: &proto.PluginCapability_Service{
						Type: proto.PluginCapability_Service_CONTROLLER_SERVICE,
					},
				},
			},
		},
	}
	return resp, nil
}

/** 插件健康检查 */
func (IdentityServer) Probe(context.Context, *proto.ProbeRequest) (*proto.ProbeResponse, error) {
	log.Println("Probe 被调用")
	resp := &proto.ProbeResponse{
		Ready: &wrappers.BoolValue{
			Value: true,
		},
	}
	return resp, nil
}
